package com.tg.appcommon.android;


import com.tange.base.toolkit.TGThreadPool;

public class OnUiThreadDelayedStatusHelper {
    private static final int CMD_INIT = 0;
    private static final int CMD_SUCCESS = 1;
    private static final int CMD_FAILD = 2;
    private int mLoadCmdStatus = 0;

    public void init(){
        mLoadCmdStatus = CMD_INIT;
    }

    public boolean isFaild(){
        return mLoadCmdStatus == CMD_FAILD;
    }

    public void setSuccess(){
        mLoadCmdStatus = CMD_SUCCESS;
    }

    public void executeOnUiThreadDelayed(final OnDelayedStatusListener onDelayedStatusListener, long delayMillis) {
        init();
        TGThreadPool.executeOnUiThreadDelayed(new Runnable() {
            @Override
            public void run() {
                if (mLoadCmdStatus == CMD_INIT){
                    mLoadCmdStatus = CMD_FAILD;
                    if (onDelayedStatusListener != null){
                        onDelayedStatusListener.doDelayedOnUiThread();
                    }
                }
            }
        }, delayMillis);
    }

    public interface OnDelayedStatusListener{
        void doDelayedOnUiThread();
    }

}
